home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 822 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. From: johnw@jove.acs.unt.edu (John R. Williams)
  2. Message-ID: <4itea2$mql@hermes.acs.unt.edu>
  3. X-Original-Date: 22 Mar 1996 05:37:06 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 22 Mar 96 06:55:39 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Using pointers after delete
  9. Organization: University of North Texas
  10. References: <4irkhs$8al@crchh327.rich.bnr.ca>
  11. X-Newsreader: TIN [version 1.2 PL2]
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMVJO9OEDnX0m9pzZAQEaLwF9ERCpdp6/Cpf/Rg/vCHnIUZZVL+3fc3Et
  14.     Bfln+7vHyh8L/LPXN8B/tyy8IyjuHuPp
  15.     =6jUQ
  16.  
  17. joe (j.) halpin (jhalpin@bnr.ca) wrote:
  18. > In 3.7.3.2.4 the January working paper says:
  19.  
  20. > 4 A deallocation function can free the storage referenced by the pointer
  21. >   given  as  its  argument and renders the pointer invalid.  The storage
  22. >   can be made available for further allocation.  An invalid pointer con-
  23. >   tains an unusable value:  it cannot even be used in an expression.
  24.  
  25. > This sounds as though, in the following:
  26.  
  27. > char *pc = new char[128];
  28. > delete pc;
  29. > pc = 0;
  30.  
  31. > it makes the final assignment (an expression) invalid.
  32.  
  33. It says that the pointer *contains an unuseable value*. Assignment to the 
  34. pointer replaces this with a potentially useable value. It's important 
  35. not to confuse an object with the value it contains.
  36.  
  37. BTW "delete pc" is required to be "delete[] pc"
  38.  
  39. > Am I misunderstanding something, or is it illegal to zero out pointers
  40. > after they've been deallocated? I'm assuming that the intent was to
  41. > disallow dereferencing of pointers that have been handed to
  42. > delete. The wording seems to disallow the above as well.
  43.  
  44. > In fact, it sounds like it also rules out things like 'if(pc == 0)
  45. > ...' after the above fragment.
  46.  
  47. No; the pointer is perfectly good now that it contains a valid value.
  48.  
  49. --
  50. class JohnWilliams: public Student, public Programmer {
  51. public:
  52.   char const *operator&() const { return "johnw@jove.acs.unt.edu"; }
  53.   char const *homepage () const { return "http://www.unt.edu/~johnw"; }
  54. };
  55. ---
  56. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  57. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  58. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  59. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  60. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  61.